Repository navigation
fix(server): omit content for 205 responses - #4262
akasakariko wants to merge 2 commits into
Conversation
A 205 response must not contain content (RFC 9110 Section 15.3.6). The HTTP/1 server now drops the body and sends `Content-Length: 0` so the response stays correctly framed. The HTTP/2 server drops the body and removes `Content-Length`. The HTTP/2 server also stops sending body data for responses to HEAD requests and removes `Content-Length` from 204 responses, as required by RFC 9110 Section 6.4.1 and RFC 9113 Section 8.1. Closes hyperium#4261
agammann
left a comment
There was a problem hiding this comment.
The HTTP/2 branch handles HEAD before the 204/205 status case. For a HEAD request whose service returns 204 No Content with a body that has an exact size hint, is_head sets a nonzero Content-Length and the else if that removes that header is skipped. The new GET 204 test and HEAD 200 test do not cover their intersection. Could the status restriction take precedence for 204/205, with a HEAD 204 (and ideally 205) regression? I reviewed the diff and surrounding framing code; I did not run tests locally.
204, 205, and 304 responses never contain content, so handle the status before the HEAD branch instead of after it, and remove Content-Length for 204 and 205 regardless of the request method Adds a regression covering HEAD requests with 204 and 205 responses
|
Addressed in the latest commit: the HTTP/2 server now checks 204, 205, and 304 status restrictions before HEAD framing and removes The new regression in Local verification: the targeted regression, |
A 205 response must not contain content (RFC 9110 Section 15.3.6), but the server still sent a body and a non-zero
Content-LengthContent-Length: 0, keeping the response correctly framedContent-Lengthfor 205 responsesContent-Lengthfor 204 responses (RFC 9113 Section 8.1)Content-LengthThe HTTP/1 behavior matches the existing handling for empty 205 responses, which already sent
Content-Length: 0Tests were added in
tests/server.rsfor HTTP/1 205 responses and HTTP/2 204, 205, HEAD, and HEAD 204/205 responsesVerification:
cargo test --features full: 333 passed, 10 ignoredcargo clippy --features full -- -D warnings: exits 0rustfmt --check --edition 2021 $(git ls-files '*.rs'): passescargo hack --no-dev-deps check --feature-powerset --depth 2 --skip ffi,tracingwith-D dead_code -D unused_imports: passesSame feature-powerset check with
tracingand--cfg hyper_unstable_tracing: passesThe description, docs, and comments (words meant for humans) are written by a human, not by an LLM.